import logging
import datetime
import sys

# 日志记录器
logger = logging.getLogger('fund allocation logger')


@staticmethod
def initLogger():
    """
    设置打印日志的级别，level级别以上的日志会打印出
    level=logging.DEBUG 、INFO 、WARNING、ERROR、CRITICAL
    """
    # 设置级别
    logger.setLevel(logging.INFO)
    formatter = logging.Formatter(
        '%(asctime)s - %(levelname)s - %(funcName)s - %(message)s')

    # 添加控制台
    streamHandler = logging.StreamHandler(sys.stderr)  # 默认是sys.stderr
    streamHandler.setFormatter(formatter)
    logger.addHandler(streamHandler)

    # 添加文件
    logFileName = f"log/{datetime.date.today().strftime('%Y_%m_%d')}.log"
    fileHandler = logging.FileHandler(logFileName)
    fileHandler.setFormatter(formatter)
    logger.addHandler(fileHandler)


@staticmethod
def log_info(info: str):
    logger.info(info)
